<?php


namespace App\Http\Controllers\Sale;


use App\Models\Order;
use App\Models\OrderGoods;
use App\Models\OrderLease;
use App\Models\SaleUser;
use App\Models\SaleUserLogin;
use App\Models\SaleLog;
use App\Models\Areas;
use App\Services\CommonService;
use App\Services\ExportService;
use App\Services\OrderService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class OrderController extends BaseController
// class OrderController
{
    /**
     * 订单列表
     * @param Request $request
     * @return json
     */
    public function orderList(Request $request){
        $input = $request->input();
        //test
        $sale_user_id = $this->users['sale_user_id'];
        // $sale_user_id = 1;

        $data = Order::saleOrderList($request,$sale_user_id);
        // dd($data);
        return ReturnMsg(CommonService::HTTP_CODE_SUCCESS,'获取成功',$data);
    }

    /**
     * 逾期订单列表
     * @param Request $request
     * @return json
     */
    public function overdueOrderList(Request $request){
        $input = $request->input();
        //test
        $sale_user_id = $this->users['sale_user_id'];
        // $sale_user_id = 1;
        $where = [];
        $where[] = ['o.status',OrderService::ORDER_STATUS_OVERDUE];

        $data = Order::saleOrderList($request,$sale_user_id,$where);
        // dd($data);
        return ReturnMsg(CommonService::HTTP_CODE_SUCCESS,'获取成功',$data);

    }

    /**
     * 获取所有区域
     * @return false|string
     */
    public function getRegion(){
        $data = Areas::handle(Areas::GetAllAreasList());
        return ReturnMsg(CommonService::HTTP_CODE_SUCCESS,'获取成功',$data);
    }



    /**
     * 订单列表导出
     * @param Request $request
     * @return false|string
     */
    public function orderListSaleExport(Request $request){
        $sale_user_id = $this->users['sale_user_id'];

        $data = ExportService::adminOrderListSaleExport($request,$sale_user_id);
        if(!$data){
            return ReturnMsg(CommonService::HTTP_CODE_FAIL,'无数据');
        }
        $params = $request->input();
        if(isset($params['order_status']) && $params['order_status']){
            $params['order_status'] = OrderService::ORDER_STATUS_NAME_LIST[$params['order_status']];
        }
        ExportService::exportFile($params,$data,ExportService::FILE_ORDER_SALE_LIST);
    }



}
